package iot.operation.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import iot.operation.constant.Constants;
import iot.operation.domain.IotDeviceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import iot.operation.mapper.IotDeviceTypeConfMapper;
import iot.operation.domain.IotDeviceTypeConf;
import iot.operation.service.IIotDeviceTypeConfService;

/**
 * 设备数据配置Service业务层处理
 * 
 * @author lujw
 * @date 2022-06-09
 */
@Service
public class IotDeviceTypeConfServiceImpl implements IIotDeviceTypeConfService 
{
    @Autowired
    private IotDeviceTypeConfMapper iotDeviceTypeConfMapper;

    /**
     * 查询设备数据配置
     * 
     * @param id 设备数据配置主键
     * @return 设备数据配置
     */
    @Override
    public IotDeviceTypeConf selectIotDeviceTypeConfById(Long id)
    {
        return iotDeviceTypeConfMapper.selectIotDeviceTypeConfById(id);
    }

    /**
     * 查询设备数据配置列表
     * 
     * @param iotDeviceTypeConf 设备数据配置
     * @return 设备数据配置
     */
    @Override
    public List<IotDeviceTypeConf> selectIotDeviceTypeConfList(IotDeviceTypeConf iotDeviceTypeConf)
    {
        return iotDeviceTypeConfMapper.selectIotDeviceTypeConfList(iotDeviceTypeConf);
    }

    /**
     * 新增设备数据配置
     * 
     * @param iotDeviceTypeConf 设备数据配置
     * @return 结果
     */
    @Override
    public int insertIotDeviceTypeConf(IotDeviceTypeConf iotDeviceTypeConf)
    {
        iotDeviceTypeConf.setCreateTime(DateUtils.getNowDate());
        return iotDeviceTypeConfMapper.insertIotDeviceTypeConf(iotDeviceTypeConf);
    }

    /**
     * 修改设备数据配置
     * 
     * @param iotDeviceTypeConf 设备数据配置
     * @return 结果
     */
    @Override
    public int updateIotDeviceTypeConf(IotDeviceTypeConf iotDeviceTypeConf)
    {
        iotDeviceTypeConf.setUpdateTime(DateUtils.getNowDate());
        return iotDeviceTypeConfMapper.updateIotDeviceTypeConf(iotDeviceTypeConf);
    }

    /**
     * 批量删除设备数据配置
     * 
     * @param ids 需要删除的设备数据配置主键
     * @return 结果
     */
    @Override
    public int deleteIotDeviceTypeConfByIds(Long[] ids)
    {
        return iotDeviceTypeConfMapper.deleteIotDeviceTypeConfByIds(ids);
    }

    /**
     * 删除设备数据配置信息
     * 
     * @param id 设备数据配置主键
     * @return 结果
     */
    @Override
    public int deleteIotDeviceTypeConfById(Long id)
    {
        return iotDeviceTypeConfMapper.deleteIotDeviceTypeConfById(id);
    }

    /**
     * 校验valCode是否唯一
     * @param iotDeviceTypeConf 设备数据配置
     * @return
     */
    public String checkValCodeUnique(IotDeviceTypeConf iotDeviceTypeConf){
        Long confId = StringUtils.isNull(iotDeviceTypeConf.getId()) ? -1L : iotDeviceTypeConf.getId();
        IotDeviceTypeConf info = iotDeviceTypeConfMapper.checkValCodeUnique(iotDeviceTypeConf);
        if (StringUtils.isNotNull(info) && info.getId().longValue() != confId.longValue())
        {
            return Constants.NOT_UNIQUE;
        }
        return Constants.UNIQUE;
    }

    /**
     * 校验valName是否唯一
     * @param iotDeviceTypeConf 设备数据配置
     * @return
     */
    public String checkValNameUnique(IotDeviceTypeConf iotDeviceTypeConf) {
        Long confId = StringUtils.isNull(iotDeviceTypeConf.getId()) ? -1L : iotDeviceTypeConf.getId();
        IotDeviceTypeConf info = iotDeviceTypeConfMapper.checkValNameUnique(iotDeviceTypeConf);
        if (StringUtils.isNotNull(info) && info.getId().longValue() != confId.longValue())
        {
            return Constants.NOT_UNIQUE;
        }
        return Constants.UNIQUE;
    }
}
